﻿using AsmShaderConverter.AsmShader;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestAsmConverter
{

    [TestClass]
    public class AsmSwizzleTests
    {

        [TestMethod]
        public void SwizzleTest()
        {
            AsmShaderFile asm = new AsmShaderFile();
            string lineOfCode = "cmp r5, -r2_abs.x, r5, c36";
            asm.AddExportRegister(new ExportRegisterNames() { offset = 0, ExportName = "ShadowMats[0]", Length = 3, registerName = "c36", typeName = "float4x3 " });
            asm.AddExportRegister(new ExportRegisterNames() { offset = 1, ExportName = "ShadowMats[0]", Length = 3, registerName = "c37", typeName = "float4x3 " });
            asm.AddExportRegister(new ExportRegisterNames() { offset = 2, ExportName = "ShadowMats[0]", Length = 3, registerName = "c38", typeName = "float4x3 " });


            AsmShaderConverter.AsmFunctions.AsmFunctionCmp asmFunction = new AsmShaderConverter.AsmFunctions.AsmFunctionCmp(lineOfCode);
            string hlsl = asmFunction.ToHLSL(asm);

            Assert.AreEqual(hlsl, "r5.xyzw = float4(-abs(r2.x) < 0 ? r5.x : ShadowMats[0]._m00,\n-abs(r2.x) < 0 ? r5.y : ShadowMats[0]._m10,\n-abs(r2.x) < 0 ? r5.z : ShadowMats[0]._m20,\n-abs(r2.x) < 0 ? r5.w : ShadowMats[0]._m30);\r\n");
        }
        [TestMethod]
        public void SwizzleTestSecondRegister()
        {
            string lineOfCode = "cmp r5, -r2_abs.x, r5, c37";
            AsmShaderFile asm = new AsmShaderFile();
            asm.AddExportRegister(new ExportRegisterNames() { offset = 0, ExportName = "ShadowMats[0]", Length = 3, registerName = "c36", typeName = "float4x3 " });
            asm.AddExportRegister(new ExportRegisterNames() { offset = 1, ExportName = "ShadowMats[0]", Length = 3, registerName = "c37", typeName = "float4x3 " });
            asm.AddExportRegister(new ExportRegisterNames() { offset = 2, ExportName = "ShadowMats[0]", Length = 3, registerName = "c38", typeName = "float4x3 " });


            AsmShaderConverter.AsmFunctions.AsmFunctionCmp asmFunction = new AsmShaderConverter.AsmFunctions.AsmFunctionCmp(lineOfCode);
            string hlsl = asmFunction.ToHLSL(asm);

            Assert.AreEqual(hlsl, "r5.xyzw = float4(-abs(r2.x) < 0 ? r5.x : ShadowMats[0]._m01,\n-abs(r2.x) < 0 ? r5.y : ShadowMats[0]._m11,\n-abs(r2.x) < 0 ? r5.z : ShadowMats[0]._m21,\n-abs(r2.x) < 0 ? r5.w : ShadowMats[0]._m31);\r\n");
        }

        [TestMethod]
        public void SwizzleTestSecondRegisterYZW()
        {
            string lineOfCode = "mov r5.yzw, c37.xxyz";
            AsmShaderFile asm = new AsmShaderFile();
            //asm.AddExportRegister(new ExportRegisterNames() { offset = 0, ExportName = "ShadowMats[0]", Length = 3, registerName = "c36", typeName = "float4x3 " });
            //asm.AddExportRegister(new ExportRegisterNames() { offset = 1, ExportName = "ShadowMats[0]", Length = 3, registerName = "c37", typeName = "float4x3 " });
            //asm.AddExportRegister(new ExportRegisterNames() { offset = 2, ExportName = "ShadowMats[0]", Length = 3, registerName = "c38", typeName = "float4x3 " });


            AsmShaderConverter.AsmFunctions.AsmFunctionMov asmFunction = new AsmShaderConverter.AsmFunctions.AsmFunctionMov(lineOfCode, false, false);
            string hlsl = asmFunction.ToHLSL(asm);

            Assert.AreEqual(hlsl, "r5.yzw = c37.xyz;");
        }
    }
}
